package com.dominator.repository;

import com.dominFramework.core.dao.SqlDao;
import com.dominFramework.core.typewrap.Dto;
import com.dominator.mybatis.dao.T_user_bankPO;
import com.dominator.utils.dao.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Repository
public class DaoBank {


    @Resource
    JdbcHelper jh;


    @Autowired
    SqlDao sqlDao;





    /**
     *  获取微信银行卡列表
      * @return
     */
    public List<Map<String,Object>> getWechatBankList(){
        StringBuilder sb=new StringBuilder();
        sb.append(" select id as bank_id,bank_name,bank_logo from t_bank where is_valid='1' ORDER BY sort ");
        return  jh.getList(sb.toString());
    }

    /**
     * 根据用户卡号查询记录
      * @param qDto
     * @return
     */
    public T_user_bankPO queryBank(Dto qDto){
        return  (T_user_bankPO)sqlDao.selectOne("UserBank.queryUserBank",qDto);
    }

    /**
     * 根据用户卡号查询记录
     * @param userId
     * @return
     */
    public List<Map<String,Object>>  queryBankList(String userId){
        StringBuilder sb=new StringBuilder();
        sb.append(" select t1.id as userBankId,t1.bank_id as bankId,t2.bank_name,CONCAT(LEFT(bank_num,4),'********',RIGHT(bank_num,4)) as bankNum,t2.bank_logo as bankLogo from t_user_bank  t1 join t_bank t2 on t1.bank_id=t2.id  where t1.is_valid='1' and t1.user_id ='"+userId+"'");
        return  jh.getList(sb.toString());
    }


}
